﻿using MediatR;
using T_settlement.API.Application.Command.InvoiceCommand;
using T_settlement.Infrastructure.Interfacec;

namespace T_settlement.API.Application.CommandHandlers.InvoiceCommandHandlers
{
    public class PDelInvoiceCommandHandlers:IRequestHandler<PDelInvoiceCommand,int>
    {
        private readonly InvoiceRepository invoiceRepository;

        public PDelInvoiceCommandHandlers(InvoiceRepository invoiceRepository)
        {
            this.invoiceRepository = invoiceRepository;
        }

        public async Task<int> Handle(PDelInvoiceCommand request, CancellationToken cancellationToken)
        {
            var Id = request.InvoiceId.Split(',').Select(x=>Convert.ToInt32(x)).ToArray();
            var list = await invoiceRepository.GetAsync(x => Id.Contains(x.InvoiceId));
            foreach (var item in list)
            {
                item.IsDel = true;
            }
            return await invoiceRepository.UpdateAsyncRange(list);
        }
    }
}
